//
//  ImageCollectionViewCell.m
//  TruckSelling
//
//  Created by enghou on 2017/9/1.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

#import "ImageCollectionViewCell.h"

@implementation ImageCollectionViewCell
{
    
    UIButton *deleteBtn;
}

@synthesize imageView;
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [self.contentView addSubview:imageView];
        
        deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        deleteBtn.frame = CGRectMake(0, 0, 20, 20);
        [deleteBtn setImage:[UIImage imageNamed:@"ic_delete"] forState:UIControlStateNormal];
        [deleteBtn addTarget:self action:@selector(deleteMySelf) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:deleteBtn];
    }
    return self;
}

-(void)setModel:(MediaItemModel *)model{
    _model = model;
    if (_model.image) {
        imageView.image = _model.image;
    }else{
        [imageView sd_setImageWithURL:_model.fileURL];
    }
}

-(void)deleteMySelf{
    if (self.del) {
        self.del(self.model);
        self.del = nil;
    }
}

-(void)dealloc{
    NSLog(@"我被释放了");
}

@end
